package com.example.jwtdemo.basecontroller;

import io.jsonwebtoken.Claims;
import org.springframework.web.bind.annotation.ModelAttribute;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class BaserController {
    protected HttpServletRequest request;
    protected HttpServletResponse response;
    protected Claims claims;
    protected String userName;

    @ModelAttribute
    public void setResAnReq(HttpServletRequest request,HttpServletResponse response) {
        this.request = request;
        this.response = response;
        Object obj = request.getAttribute("user_claims");
        if (null != obj){
            this.claims = (Claims) obj;
            this.userName = (String)claims.get("userName");
        }
    }
}
